package com.isoftstone.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.isoftstone.pojo.Users;
import com.isoftstone.service.UserService;

@Controller
public class LoginController {

	@Autowired
	private UserService userService;
	
	//登录操作
	@RequestMapping(path="/login", method = RequestMethod.POST)
	public ModelAndView login(String username, String password,HttpServletRequest res,HttpServletResponse resp) {
		ModelAndView mv = new ModelAndView();
		Users user = userService.login(username, password);
		if(user==null) {
			mv.setViewName("error");
		}else {
			res.getSession().setAttribute("user", user);
			mv.addObject("user",user);
			mv.setViewName("manage");
		}
		return mv;
	}
	//主页
	@RequestMapping("/index")
	public String index() {
		return "welcome";
	}
	

}
